<template>
  <s-popup v-model="show" position="center" round>
    <view class="popupContainer">
      <view class="popupTitle">{{ title }}</view>
      <uni-easyinput
        v-model="inputValue"
        :placeholder="placeholder"
        clearable
      />
      <view class="buttonGroup">
        <s-button type="default" size="small" @click="$emit('cancel')">
          取消
        </s-button>
        <s-button
          type="primary"
          size="small"
          @click="$emit('confirm', inputValue)"
          :loading="loading"
        >
          确定
        </s-button>
      </view>
    </view>
  </s-popup>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: "复制问卷"
    },
    placeholder: {
      type: String,
      default: "请输入新名称"
    },
    loading: {
      type: Boolean,
      default: false
    },
    initialValue: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      inputValue: ""
    };
  },
  watch: {
    initialValue: {
      immediate: true,
      handler(val) {
        this.inputValue = val;
      }
    }
  }
};
</script>

<style scoped>
.popupContainer {
  width: 600rpx;
  padding: 40rpx;
  background-color: #fff;
  border-radius: 24rpx;
}

.popupTitle {
  font-size: 32rpx;
  font-weight: bold;
  text-align: center;
  margin-bottom: 40rpx;
  color: #333;
}

.buttonGroup {
  display: flex;
  justify-content: space-between;
  margin-top: 50rpx;
}

.buttonGroup button {
  flex: 1;
  margin: 0 10rpx;
}
</style>